home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 219 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.9 KB

  1. Path: lrz-muenchen.de!sun2!ua302aa
  2. From: ua302aa@sun2.lrz-muenchen.de (Kurt Watzka)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: qsort help
  5. Date: 3 Jan 1996 11:57:16 GMT
  6. Organization: Leibniz-Rechenzentrum, Muenchen (Germany)
  7. Distribution: world
  8. Message-ID: <4cdqus$j5i@sparcserver.lrz-muenchen.de>
  9. References: <4ccio7$7c0@charm.magnus.acs.ohio-state.edu> <4cdomq$jgt@dub-news-svc-5.compuserve.com>
  10. NNTP-Posting-Host: sun2.lrz-muenchen.de
  11.  
  12. stuart.hayes@baesema.co.uk writes:
  13.  
  14. >xiaoyi@bmecg.bme.ohio-state.edu (Xiaoyi Wu) wrote:
  15.  
  16. >>Hi, I am having some problems with the qsort routine.
  17.  
  18.  
  19. >>int (*compar)(int *a, int *b)
  20. >Function declaration should be:
  21. >int compar(int *a, int *b)
  22. >Should also declare function in header file or top of source for
  23. >completeness
  24.  
  25. What kind of "completeness" can be reached by declaring a function
  26. in a header file or "top of source". A functions definition provides
  27. enough information if it appears before the point of use.
  28.  
  29. >>{
  30. >>  if (*a < *b) return -1;
  31. >>  else if (*a == *b) return 0;
  32. >>  else return 1;
  33. >>}
  34.  
  35.  
  36. >Alternatively to declaring function in header file could just declare
  37. >in the function below:
  38.  
  39. >>int return_moved_contour(int ix, int iy)
  40. >>{
  41. >int (*compar)(int *a, int *b);
  42.  
  43. This declares a pointer to a function
  44.  
  45. [some code that does not set the variable "compar" edited]
  46.  
  47. >>    qsort(y_coord, count, sizeof(int), compar);
  48.  
  49. This uses an uninitialized pointer to a function. You could get another
  50. diagnostic message for this from a good compiler. If the compiler does
  51. _not_ reject this code, the results can be very interesting.
  52.  
  53. >This is a first preliminary stab at this, haven't tried it.
  54. >Hope of some help.
  55.  
  56. I'm afraid that the chances of this article to help anyone are pretty poor.
  57. But nothing is in vain; it can still serve as a bad example ;-).
  58.  
  59. Kurt
  60. --
  61. | Kurt Watzka                             Phone : +49-89-2180-6254
  62. | watzka@stat.uni-muenchen.de
  63. | ua302aa@sunmail.lrz-muenchen.de
  64.